package com.itguigu.fruit.demo;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class demo05 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection conn = DriverManager.getConnection("jdbc:mysql:///fruitdb?rewriteBatchedStatements=true", "root", "123456");
        System.out.println(conn==null ? "连接失败":"链接成功");
        //3.编写SQL语句
        String sql="insert into t_person values(null,?)";
//        4.
        PreparedStatement psmt=conn.prepareStatement(sql);
        for (int i = 1; i <= 1000; i++) {
//            5.具体数值
            psmt.setString(1,"用户"+i);
            psmt.addBatch();
        }
        psmt.executeBatch();
//
//        psmt.setInt(2,2);
//        psmt.setInt(3,150);
//        psmt.setString(4,"ok");
        //6.返回影响行数
//        int count=psmt.executeUpdate();
//        System.out.println(count>0 ? "添加成功":"添加失败");
//        7.释放链接
        psmt.close();
        conn.close();
    }

}
